package cn.bbs.ba.mi;

import java.security.MessageDigest;

public class Encryption {
	private static char encry(char c) {
		if (c >= 97 && c <= 123) {
			if (c == 'x') {
				c = 'a';
			} else if (c == 'y') {
				c = 'b';
			} else if (c == 'z') {
				c = 'c';
			} else {
				c = (char) (c + 3);
			}
		}
		return c;
	}

	public static String encry(String str) {
		StringBuffer sb = new StringBuffer();
		if (str == null) {
			throw new RuntimeException("û�м�����Ϣ");
		} else {
			str = md5Encode(str);
			// 是否进行二次加密
//			for (char c : str.toCharArray()) {
//				sb.append(encry(c));
//			}
		}
		return str.toString();
	}

	/**
	 * 
	 * md5 ����
	 * 
	 * @param str
	 * 
	 * @return
	 */

	public static String md5Encode(String str)

	{

		StringBuffer buf = new StringBuffer();

		try

		{

			MessageDigest md5 = MessageDigest.getInstance("MD5");

			md5.update(str.getBytes());

			byte bytes[] = md5.digest();

			for (int i = 0; i < bytes.length; i++)

			{
				String s = Integer.toHexString(bytes[i] & 0xff);

				if (s.length() == 1) {
					buf.append("0");
				}
				buf.append(s);
			}
		}
		catch (Exception ex)
		{
		}

		return buf.toString();

	}
}
